<template>
  <div class="sceneTask result">
      <div class="scenepricingForm" style="border:solid 1px #ccc;">
    <el-form
      :model="searchForm"
      ref="searchRef"
      style="margin-top:10px"
      label-width="100px"
      label-position="right"
      size="mini"
    >
      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="头寸数据表：" prop="positions">
            <el-select v-model="searchForm.pdName" placeholder="请选择" style="width:100%">
              <el-option
                v-for="item in positionOptions"
                :key="item.pdPhyName"
                :label="item.pdCName"
                :value="item.pdPhyName"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="情景：" prop="scene">
            <el-select
              v-model="searchForm.sceneName"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in sceneOptions"
                :key="item.sceneCode"
                :label="item.sceneName"
                :value="item.sceneCode"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="数据日期：" prop="dataDate" >
            <el-date-picker
              v-model="searchForm.dataDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder=""
              style="width:100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <div v-show="shrink">
      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="账号：" prop="accountNum">
            <el-input v-model="searchForm.accountNum" maxlength="32"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="机构：" prop="orgCode">
            <ftp-organ-tree
               style="height:32px;"
                v-model="searchForm.orgCode"
                :mulSelect="false"
               >   
            </ftp-organ-tree>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <!-- <el-form-item label="科目：" prop="accountNum"> -->
          <!-- <el-input v-model=".accountNum" maxlength="32"></el-input> -->
          <el-form-item label="科目: " prop="subjectCode">
             <ftp-tree
                style="height: 32px"
                v-model="searchForm.subjectCode"
                dictCode="GeneralLedger"
                :mulSelect="false"

               >   
            </ftp-tree>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="产品：" prop="productCode">
            <ftp-tree
            style="height: 32px"
                v-model="searchForm.productCode"
                dictCode="productCd"
                :mulSelect="false"
               >   
            </ftp-tree>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="行业：" prop="industryCode">
              <ftp-tree
                style="height: 32px"
                v-model="searchForm.industryCode"
                dictCode="Industry"
                :mulSelect="false"
               >   
            </ftp-tree>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="币种：" prop="currencyCode">
            <el-select
              v-model="searchForm.currencyCode"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in currencyOption"
                :key="item.currencyId"
                :label="item.currencyName"
                :value="item.currencyId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="起息日：" prop="orgDate">
            <el-date-picker
              v-model="searchForm.orgDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder=""
              style="width:100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="6" :offset="2">
          <el-form-item label="利率类型：" prop="rateTypeCd">
            <el-select
              v-model="searchForm.rateTypeCd"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in rateTypeCdOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="支付类型：" prop="payTypeCd">
            <el-select
              v-model="searchForm.payTypeCd"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in payTypeCdOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="重定价频率：" prop="repriceFreq">
            <el-col :span="10">
              <el-input
                v-model.trim="searchForm.repriceFreqL"
                maxlength="40"
              ></el-input>
            </el-col>
            <el-col :span="14">
              <el-select
                v-model="searchForm.date"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in dateOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="原始期限：" prop="orgTerm">
            <!-- <el-form-item label="指定期限：" prop="assignTerm"> -->
            <el-col :span="10">
              <el-input
                v-model.trim="searchForm.orgTermL"
                maxlength="40"
              ></el-input>
            </el-col>
            <el-col :span="14">
              <el-select
                v-model="searchForm.orgTermdate"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in dateOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="6" :offset="2">
          <el-form-item label="定价编号：" prop="taskCode">
            <el-input v-model="searchForm.taskCode" maxlength="32"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6" :offset="1">
          <el-form-item label="定价状态：" prop="status">
            <el-select
              v-model="searchForm.status"
              placeholder="请选择"
              style="width:100%"
            >
              <el-option
                v-for="item in statusOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      </div>
       <el-row class="container" style="text-align:center">
          <el-col style="margin-bottom:10px;" class="content-left">
            <el-button @click="searchFunc()">查询</el-button>
            <el-button @click="reset()">重置</el-button>
                        <i
              class="el-icon-d-caret shrink"
              :title="shrink ? '收缩' : '展开'"
              @click="shrink = !shrink"
            ></i>
          </el-col>
        </el-row>
         </el-form>
  </div>
      <el-row class="container">
        <el-col style="margin:10px 0px 10px 0px" class="content-left">
          <el-button @click="expExcel()">导出</el-button>
          <el-button @click="showCashFlow()">查看现金流</el-button>
          <el-button @click="toForm()">查看详情</el-button>
        </el-col>
      </el-row> 

      <el-table
        ref="multipleModelTable"
        :data="tableModelData"
        style="width: 100%"
        @row-click="authorizeModelFor"
      >
        <el-table-column
          width="55"
          type="selection"
          
        ></el-table-column>
        <el-table-column
          prop="TASKCODE"
          label="重定价编号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ACCOUNTNUM"
          label="账号"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="DATADATE"
          label="数据日期"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ORGCODE_DISP"
          label="机构"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="PRODUCTCODE_DISP"
          label="产品"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="SUBJECTCODE_DISP"
          label="科目"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="CURRENCYCODE_DISP"
          label="币种"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="CURBAL"
          label="当前余额"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ORGDATE"
          label="起息日"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="INTRATE"
          label="对客利率"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="TRANSRATE"
          label="基础转移价格"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="FINALTRANSRATE"
          label="最终转移价格"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="COMPRICING"
          label="组合定价调整项"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="TRANSIE"
          label="转移收支"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="BREAKCHARGERESULT"
          label="BreakCharge结果"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="BREAKFUNDINGRESULT"
          label="BreakFunding结果"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="YEARPROFITLOSS"
          label="年度累计损益"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="PROFITANDLOSS"
          label="累计损益"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="HISTORYBALSUM"
          label="历史余额累计"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ORGINTRATE"
          label="起息日的执行利率"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="LASTREPRICEBAL"
          label="上次重定价余额"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ORGBAL"
          label="原始余额"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="MATDATE"
          label="到期日"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="ORGTERM"
          label="原始期限"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="REPRICETYPECD"
          label="重定价类型代码"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="LASTREPRICEDATE"
          label="上次重定价日期"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="NEXTREPRICEDATE"
          label="下次重定价日期"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="REPRICEFREQ"
          label="重定价频率"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="PAYTYPECD_DISP"
          label="支付类型"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="LASTPAYDATE"
          label="上次支付日"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="NEXTPAYDATE"
          label="下次支付日"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="PRICINGSTATUS"
          label="定价状态"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="RESULTINFO"
          label="结果信息"
          :show-overflow-tooltip="true"
        ></el-table-column>
      </el-table>
      <!-- 分页插件 -->
      <pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchForm.page"
        :page-size="searchForm.size"
        @refresh="searchFunc"
        :total="total"
      ></pagination>
   
<!-- 查看现金流 -->
    <el-dialog
      title="查看现金流"
      v-dialogDrag
      width="70%"
      top="5%"
      :visible.sync="showCashFlowOper"
    >
      <cash-flow :param="cashFlowParam" :flag="showCashFlowOper"></cash-flow>
      <div slot="footer">
        <el-button @click="showCashFlowOper = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 查看详情页面 -->
    <el-dialog
      v-dialogDrag
      title="查看详情"
      :visible.sync="resultFormDi"
      append-to-body
      width="55%"
      top="2%"
      @close="cancel"
    >
      <!-- 引入 -->

      <resultForm
        ref="resultForm"
        :id="id"
        :positionTableFix="positionTableFix"
      ></resultForm>
      <!-- :mulSelect="mulSelect" -->
      <div slot="footer">
        <!-- <el-button @click="saveFunc">确 定</el-button> -->
        <el-button @click="resultFormDi = false">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { pricingTask } from "@/api/index";
import cashFlow from "@/views/ftpManage/pricingManage/pricingTask/pricingCashFlow";
import { getDict } from "@/api/getDict";
import { publicManage_pub } from "@/api/index";
import upperTemplate from "@/components/upperTemplate.vue";
import ruleDefComponents from "@/components/ca/ruleDefComponents";
import ftpTree from '@/components/ftp/ftpRelationTree'
import resultForm from "./sceneResult_form";
import ftpOrganTree from '@/components/ftp/ftpCurrentUserOrganTree';
export default {
  data() {
    return {
      shrink: true,
      //查看现金流
      showCashFlowOper: false,
      cashFlowParam: {},
      sceneOptions: [],
      //查看详情
      positionTableFix: "",
      id: "",
      resultFormDi: false,
      product: "",
      org: "",
      industry: "",
      subject: "",
     
      searchForm: {
        pdName: "default",
        dataDate: new Date(),
        page: 1,
        size: 15,
      },
      //币种
      currencyOption: [],
      //年月日
      dateOption: [],
      //头寸数据表
      positionOptions: [],
      //定价状态
      statusOption: [],
      //支付类型
      payTypeCdOption: [],
      //利率类型
      rateTypeCdOption: [],
      tableModelData: [],
      total: null,
    };
  },
  watch: {},
  components: {
    upperTemplate,
    ruleDefComponents,
    resultForm,
    ftpTree,
    ftpOrganTree,
    cashFlow

  },
  created() {
    this.getDict("ftp_pricing_status");
    this.getDict("ftp_cp_rate_type_cd");
    this.getDict("ftp_cp_pay_type_cd");
    this.getDict("ftp_cp_time_type");
    // this.findPositionTableList();
    this.queryDimCurrency();
    this.findPositionTableList();
    this.findSceneCodeList();
  },
  computed: {},
  mounted() {},
  methods: {
        expExcel(){
         //判断是根据条件查询  还是根据选择查询
          let data = {
        page: this.searchForm.page+1,
        size: this.searchForm.size,
        accountNum: this.searchForm.accountNum,
        currencyCode: this.searchForm.currencyCode,
        currencyCode_text: "",
        dataDate: this.searchForm.dataDate,
        industryCode: this.searchForm.industryCode,
        industryCode_text: "",
        order: "",
        orderBy: "",
        orgCode: this.searchForm.orgCode,
        orgCode_text: "",
        orgDate: this.searchForm.orgDate,
        orgTerm: this.searchForm.orgTermL+this.searchForm.orgTermdate,
        payTypeCd: this.searchForm.payTypeCd,
        positionResult: {},
        positionTableFix: this.searchForm.pdName,
        pricingStatus: this.searchForm.status,
        productCode: this.searchForm.productCode,
        productCode_text: "",
        rateTypeCd: this.searchForm.rateTypeCd,
        repriceFreq: this.searchForm.repriceFreqL+this.searchForm.date,
        subjectCode: this.searchForm.subjectCode,
        subjectCode_text: "",
      };
      pricingTask.expSceneResult(data).then(response => {
           console.log(response,"response");
        if (response.code == 500) {
          this.$message.error(response.message);
        } else if (response) {
          console.log(decodeURI(response.headers["content-disposition"]));
          var filename = decodeURI(
            response.headers["content-disposition"]
          ).split("=")[1];
          let contenttype =
            filename.substring(filename.lastIndexOf("."), filename.length) ===
            "xlsx"
              ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
              : "application/vnd.ms-excel;charset=utf-8";
          var blob = new Blob([response.data], {
            type: contenttype
          });
          if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, filename);
          } else {
            var downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = filename; //下载后文件名
            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
          }
          this.$message.success("导出成功");
        } else {
          this.$message.error(response.message || "获取失败");
        }
      });
    },
    showCashFlow() {
      //选中的数据
      let selects = this.$refs.multipleModelTable.selection;
      if (selects.length != 1) {
        return this.$message.warning("请选择一条数据查看现金流");
      }
      if (selects[0].RESULTINFO != "3") {
        this.$message.warning("该结果不是现金流法，故无法查看现金流！");
        return;
      }
      let row = selects[0];
      console.log("row====" + JSON.stringify(row));
      this.cashFlowParam = {
        dataDt: row.DATADATE,
        acctNo: row.ACCOUNTNUM,
        tableName: this.searchForm.pdName,
        sceneCode: this.searchForm.sceneCode
      };
      this.showCashFlowOper = true;
    },
    findSceneCodeList() {
      pricingTask.findSceneCodeList().then((res) => {
        if (res.code == 200) {
          this.sceneOptions = res.datas;
          console.log(res, "findall查出来的数===========");
        } else {
          this.$message.error("情景表查询失败");
        }
      });
    },
    toForm() {
      let selection = this.$refs.multipleModelTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      this.id =
        selection[0].ACCOUNTNUM +
        "$" +
        selection[0].TASKCODE +
        "$" +
        selection[0].DATADATE;
      this.positionTableFix = this.searchForm.pdName;
      console.log("id=" + this.id + "position头寸=" + this.positionTableFix);
      this.resultFormDi = true;
    },
    reset() {
      this.searchForm = {
        page: this.searchForm.page,
        size: this.searchForm.size,
      };
    },
    searchFunc() {
          pricingTask.checkCurrentOrganPrivilege().then(resp => {
        if (resp.code == 200) {
                  let data = {
        page: this.searchForm.page + 1,
        size: this.searchForm.size,
        accountNum: this.searchForm.accountNum,
        currencyCode: this.searchForm.currencyCode,
        currencyCode_text: "",
        dataDate: this.searchForm.dataDate,
        industryCode: this.searchForm.industryCode,
        industryCode_text: "",
        order: "",
        orderBy: "",
        orgCode: this.searchForm.orgCode,
        orgCode_text: "",
        orgDate: this.searchForm.orgDate,
        orgTerm: this.searchForm.orgTermL + this.searchForm.orgTermdate,
        payTypeCd: this.searchForm.payTypeCd,
        positionResult: {},
        sceneCode: this.searchForm.sceneName,
        positionTableFix: this.searchForm.pdName,
        pricingStatus: this.searchForm.status,
        productCode: this.searchForm.productCode,
        productCode_text: "",
        rateTypeCd: this.searchForm.rateTypeCd,
        repriceFreq: this.searchForm.repriceFreqL + this.searchForm.date,
        subjectCode: this.searchForm.subjectCode,
        subjectCode_text: "",
        taskCode: this.searchForm.taskCode,
      };
      console.log(data, "传递的数据");
      pricingTask.sceneResult(data).then((res) => {
        if (res.code == 200) {
          this.tableModelData = res.datas.rows;
          console.log(res, "情景结果查出来的数===========");
        } else {
          this.$message.error("查询失败");
        }
      });
         } else {
          this.$message.warning(resp.message);
        }
      });


    },
    queryDimCurrency() {
      let data = {
        currencyCode: "",
        currencyDescribe: "",
        currencyFlag: "",
        currencyName: "",
        currencySign: "",
        order: "",
        orderBy: "",
        page: 0,
        size: 0,
        status: "",
      };
      console.log(data, "data");
      publicManage_pub.currencyManageQuery(data).then((res) => {
        if (res.code == 200) {
          this.currencyOption = res.data;
          console.log(res, "chadaodeshujv===========");
        } else {
          this.$message.error(res.message);
        }
      });
    },
    findPositionTableList() {
      pricingTask.findPositionTableList().then((res) => {
        if (res.code == 200) {
          this.positionOptions = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },                                         
    getDict(data) {
      getDict(data).then((res) => {
        if (res.code == 200) {
          if (data == "ftp_pricing_status") {
            this.statusOption = res.datas;
          } else if (data == "ftp_cp_rate_type_cd") {
            this.rateTypeCdOption = res.datas;
          } else if (data == "ftp_cp_pay_type_cd") {
            this.payTypeCdOption = res.datas;
          } else {
            this.dateOption = res.datas;
          }
        } else {
          this.$message.error(res.message);
        }
      });
    },
    cancel() {
      this.resultFormDi = false;
    },
    //点击行选中
    authorizeModelFor(row) {
      if (this.$refs.multipleModelTable) {
        this.$refs.multipleModelTable.clearSelection();
      }
      this.$refs.multipleModelTable.toggleRowSelection(row, true);
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
      console.log(val, "每页数");
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
      console.log(val, "当前页");
    },
  },
};
</script>

<style lang="scss" scoped>
.dialogSearchBox {
  header {
    text-align: center;
    span {
      margin: 0 20px;
    }
  }
}
.selectBox {
  background: url("~@/assets/images/popWindow_arrow.gif");
  background-repeat: no-repeat;
  height: 26px;
  width: 23px;
  position: absolute;
  right: 0;
  top: 5px;
  cursor: pointer;
}
.shrink {
  position: absolute;
  right: 8px;
  bottom: 8px;
  color:#415378;
  font-size: 20px;
  border: 1px solid #ccc;
  cursor: pointer;
  padding: 3px;
  border-radius: 3px;
}
.shrink:hover {
  border: 1px solid #415378;
}
</style>

